package io.github.eric.urpc.standalone.client;

import io.github.eric.urpc.client.Client;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class FriendManager {
    private Client client;

    private List<String> allFriends = new ArrayList<>();
    private Map<String, String> tmpFriends;

    public FriendManager(Client client) {
        this.client = client;
    }

    public List<String> getAllFriends() {
        return allFriends;
    }

    public void startNewFriendsList() {
        tmpFriends = new ConcurrentHashMap<>();
    }

    public void addFriends(List<String> users, String selfId) {
        if (tmpFriends == null) {
            return;
        }
        for (String userId : users) {
            tmpFriends.put(userId, "");
        }
    }

    public void finishNewFriendsList() {
        if (tmpFriends == null) {
            return;
        }
        List<String> tmp = new ArrayList<>();
        tmp.addAll(tmpFriends.keySet());
        allFriends = tmp;
        tmpFriends = null;
    }
}
